package com.itic.appbase.applications.webservice.cxf.impl;

import com.itic.appbase.applications.sys.org.persistence.model.Org;
import com.itic.appbase.applications.sys.org.service.OrgService;
import com.itic.appbase.applications.sys.user.persistence.model.SysUser;
import com.itic.appbase.applications.sys.user.persistence.model.SysUserExample;
import com.itic.appbase.applications.sys.user.persistence.model.SysUserExample.Criteria;
import com.itic.appbase.applications.sys.user.service.SysUserService;
import com.itic.appbase.applications.webservice.cxf.beans.UserWB;
import com.itic.appbase.applications.webservice.cxf.sei.HelloService;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.appbase.framework.utils.ValueHelper;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@WebService(endpointInterface = "com.itic.appbase.applications.webservice.cxf.sei.HelloService")
@Component
public class HelloServiceImpl
        implements HelloService {
    @Autowired
    SysUserService sysUserService;
    @Autowired
    OrgService     orgService;

    /*
     * (non-Javadoc)
     * 
     * @see com.itic.appbase.applications.webservice.cxf.rest.HelloService_Rest#sayHi(java.lang.String)
     */
    @Override
    public String sayHi(String text) {
        return "123456" + text;
    }
    /*
     * (non-Javadoc)
     * 
     * @see com.itic.appbase.applications.webservice.cxf.rest.HelloService_Rest#getUserInfo(java.lang.String)
     */
    @Override
    public UserWB getUserInfo(String input) {
        UserWB userwb = new UserWB();
        String username = input;
        if (StringHelper.isBlank(username)) {
            username = "test";
        }
        SysUserExample example = new SysUserExample();
        Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);
        SysUser user = sysUserService.list(example).get(0);
        if (null != user) {
            Org org = this.orgService.get(user.getOrg());
            userwb.setOrgname(null != org ? org.getName() : "");
            ValueHelper.model2vo(user, userwb);

        }
        return userwb;
    }
}
